#pragma once
#include <iostream>

#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>

#include <queue>
#include <mutex>
#include <memory>

namespace net = boost::asio;
using namespace boost::beast;
using namespace boost::beast::websocket;

class Connection : public std::enable_shared_from_this<Connection> {
public:
    explicit Connection(net::io_context &ioc);

    std::string GetUuid();

    net::ip::tcp::socket &GetSocket() const;

    void AsyncAccept();

    void Start();

    void AsyncSend(const std::string &msg);

    void SendCallBack(const std::string &msg);

private:
    net::io_context &_ioc;
    std::unique_ptr<stream<tcp_stream> > _ws_ptr;
    std::string _uuid;
    flat_buffer _recv_buffer;
    std::queue<std::string> _send_que;
    std::mutex _send_mtx;
};
